#include<stack>
#include<string>
using namespace std;
class Solution {
public:
    string decodeString(string s) {
        int size = s.size();
        stack<int> sti;
        stack<string> sts;
        sts.push("");
        for (int i = 0; i < size; ) {
            if (s[i] >= '0' && s[i] <= '9') {
                int num = 0;
                while (i < size && s[i] >= '0' && s[i] <= '9') {
                    num *= 10;
                    num += s[i] - '0';
                    i++;
                }
                sti.push(num);
            }
            else if (s[i] == '[') {
                i++;
                string tmp;
                while (i < size && s[i] >= 'a' && s[i] <= 'z')tmp += s[i++];
                sts.push(tmp);
            }
            else if (s[i] >= 'a' && s[i] <= 'z') {
                string x = sts.top();
                x += s[i];
                sts.pop();
                sts.push(x);
                i++;
            }
            else {
                string ret;
                int j = sti.top();
                sti.pop();
                while (j--)ret += sts.top();
                sts.pop();
                ret = sts.top() + ret;
                sts.pop();
                sts.push(ret);
                i++;
            }
        }
        return sts.top();
    }
};
int main() {
    return 0;
}